package com.wxy.ej.flow.modules.taskflow.service.nodeExecuteStrategy.strategy.ui;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSONObject;
import com.rt.easyjava.common.base.Result;
import com.wxy.ej.flow.modules.taskflow.dto.DataDto;
import com.wxy.ej.flow.modules.taskflow.dto.NodeDto;
import com.wxy.ej.flow.modules.taskflow.service.nodeExecuteStrategy.NodeStrategy;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UITokenNodeStrategy extends NodeStrategy {
    @Override
    public Result action(NodeDto node, JSONObject flowDataJson, DataDto dataDto) {
        Object inParam = dataDto.getUiInParam();

        // object to json
        String json = JSONUtils.toJSONString(inParam);
        JSONObject inParamJson = JSONObject.parseObject(json);
        System.out.println("inParamJson");
        System.out.println(inParamJson);

        JSONObject urlQueryData = inParamJson.getJSONObject("urlQueryData");
        System.out.println(urlQueryData);
        if (urlQueryData==null) {
            return Result.builder().fault("校验失败");
        }

        String token = urlQueryData.getString("token");
        if (token==null || !token.equalsIgnoreCase("aaa")) {
            return Result.builder().fault("校验失败");
        }


        return Result.builder();
    }
}
